import { request } from '../request';

/** 曲线管理API */

// 曲线定义API
export function fetchCurveDefinitions() {
  return request<Api.Curve.CurveDefinition[]>({
    url: '/api/curve/definition',
    method: 'get'
  });
}

export function fetchCurveDefinitionById(id: number) {
  return request<Api.Curve.CurveDefinition>({
    url: `/api/curve/definition/${id}`,
    method: 'get'
  });
}

export function createCurveDefinition(curve: Api.Curve.CurveDefinitionDTO) {
  return request<Api.Curve.CurveDefinition>({
    url: '/api/curve/definition',
    method: 'post',
    data: curve
  });
}

export function updateCurveDefinition(id: number, curve: Api.Curve.CurveDefinitionDTO) {
  return request<Api.Curve.CurveDefinition>({
    url: `/api/curve/definition/${id}`,
    method: 'put',
    data: curve
  });
}

export function deleteCurveDefinition(id: number) {
  return request({
    url: `/api/curve/definition/${id}`,
    method: 'delete'
  });
}

// 利率曲线重估API
export function fetchRateCurveRevaluationsByMappingId(mappingId: number) {
  return request<Api.Curve.RateCurveRevaluation[]>({
    url: `/api/curve/rate-revaluations/mapping/${mappingId}`,
    method: 'get'
  });
}

export function fetchRateCurveRevaluationsByCurveId(curveId: number) {
  return request<Api.Curve.RateCurveRevaluation[]>({
    url: `/api/curve/revaluation/curve/${curveId}`,
    method: 'get'
  });
}

export function fetchRateCurveRevaluationById(dataId: number) {
  return request<Api.Curve.RateCurveRevaluation>({
    url: `/api/curve/rate-revaluations/${dataId}`,
    method: 'get'
  });
}

export function createRateCurveRevaluation(data: Api.Curve.RateCurveRevaluationDTO) {
  return request<Api.Curve.RateCurveRevaluation>({
    url: '/api/curve/rate-revaluations',
    method: 'post',
    data
  });
}

export function updateRateCurveRevaluation(dataId: number, data: Api.Curve.RateCurveRevaluationDTO) {
  return request<Api.Curve.RateCurveRevaluation>({
    url: `/api/curve/rate-revaluations/${dataId}`,
    method: 'put',
    data
  });
}

export function deleteRateCurveRevaluation(dataId: number) {
  return request({
    url: `/api/curve/rate-revaluations/${dataId}`,
    method: 'delete'
  });
}

export function batchDeleteRateCurveRevaluations(dataIds: number[]) {
  return request({
    url: '/api/curve/rate-revaluations/batch',
    method: 'delete',
    data: { dataIds }
  });
}
